#!/usr/bin/python
#coding:utf-8
'''
时间工具类
'''
import time
import datetime

strFormat="%Y-%m-%d %H:%M:%S"

def formatUntime(timeTmp):
    '''
    常用格式转时间戳
    '''
    timeArray = time.strptime(timeTmp, strFormat)
    timeStamp = int(time.mktime(timeArray))
    return timeStamp

def formatTime(timeTmp):
    '''
    时间戳转常用格式
    '''
    import time
    time_local = time.localtime(timeTmp)
    dt = time.strftime(strFormat, time_local)
    return dt

def getTime():
    '''
    获取当前时间
    '''
    dt = time.strftime(strFormat, time.localtime())
    print('毫秒',datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3])
    return dt

def gethour():
    '''
    获取当前时间小时和分钟
    '''
    timeNow=datetime.datetime.now()
    print("hour:",timeNow.hour,"minute:",timeNow.minute)


def checkRestDat():
    '''
    判断当天是否为周六日
    return 0 为休息日 1 为工作日
    '''
    import calendar
    currentdate = datetime.date.today()
    year= currentdate.year
    month = currentdate.month
    day = currentdate.day
    currentday =calendar.weekday(year,month,day)

    #判断当天是否为周末  0 为周一
    if currentday > 5:
        return 0
    else:
        return 1